package io.renren.modules.bike.service.impl;

import io.renren.modules.bike.entity.CategoryEntity;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.bike.dao.MoneyDao;
import io.renren.modules.bike.entity.MoneyEntity;
import io.renren.modules.bike.service.MoneyService;


@Service("moneyService")
public class MoneyServiceImpl extends ServiceImpl<MoneyDao, MoneyEntity> implements MoneyService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        IPage<MoneyEntity> page = null;
        if (key != null) {
            page = this.page(
                    new Query<MoneyEntity>().getPage(params),
                    new QueryWrapper<MoneyEntity>().like("money", key)
            );
        } else {
            page = this.page(
                    new Query<MoneyEntity>().getPage(params),
                    new QueryWrapper<MoneyEntity>()
            );
        }

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageUser(Map<String, Object> params, Long userId) {
        IPage<MoneyEntity> page = this.page(
                new Query<MoneyEntity>().getPage(params),
                new QueryWrapper<MoneyEntity>().eq("uId", userId)
        );

        return new PageUtils(page);
    }

    @Override
    public MoneyEntity selectOne(Long userId) {
        return baseMapper.selectOne(new QueryWrapper<MoneyEntity>().eq("uId", userId));
    }

}
